package com.spa.application.service.admin;

import com.spa.application.command.admin.AdminRoleAddCommand;
import com.spa.application.command.admin.AdminRoleEditCommand;
import com.spa.application.dto.PageResult;
import com.spa.application.dto.admin.ResourceDTO;
import com.spa.application.dto.admin.SysRoleDto;
import com.spa.domain.service.SysRoleService;
import com.spa.infrastructure.mapper.SysRoleMapperStruct;
import com.spa.infrastructure.repository.condition.SysRoleCondition;
import com.spa.infrastructure.repository.po.SysRolePO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

@Service
@Slf4j
public class AdminSysRoleApplicationService {

    @Resource
    private SysRoleService sysRoleService;

    @Transactional
    public void addRole(AdminRoleAddCommand command) {
        SysRolePO sysRolePO = sysRoleService.addRole(command);
    }

    @Transactional
    public void editRole(AdminRoleEditCommand command) {
        sysRoleService.editRole(command);
    }

    public PageResult<SysRoleDto> pageRole(SysRoleCondition condition) {
        PageResult<SysRoleDto> sysRoleDtoPageResult = SysRoleMapperStruct.INSTANCE.entity2Dto4Page(sysRoleService.pageRole(condition));
        return sysRoleDtoPageResult;
    }

    public List<SysRoleDto> getAllRole() {
        return SysRoleMapperStruct.INSTANCE.entity2DtoList(sysRoleService.listAllRole());
    }

    public SysRoleDto detailsById(Long roleId) {
        SysRoleDto sysRoleDto = SysRoleMapperStruct.INSTANCE.entity2Dto(sysRoleService.infoById(roleId));
        return sysRoleDto;
    }

    /**
     * 查询该角色拥有的资源.
     *
     * @return 资源列表
     */
    public List<ResourceDTO> listOwned(String roleId) {
            return Collections.emptyList();
    }

}
